<template>
  <div class="receipt">
    <van-nav-bar
      title="标题"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
          <van-address-list
            v-model="chosenAddressId"
            :list="list"
            @add="onAdd"
            @edit="onEdit"
          />

  </div>
</template>

<script>
import { getreceiptapi} from "../../api/receipt";
import { Toast } from "vant";
export default {
  data() {
    return {
      totalCount:"",
      chosenAddressId:1,
      list: [],
      arr:[],
    };
  },
  computed: {},
  watch: {},

  methods: {
    //返回上一步
    onClickLeft() {
      Toast("返回");
      this.$router.go(-1);
    },
    //获取收货信息列表
    async getreceipt() {
      const per = 10;
      const page = 1;
      const result = await getreceiptapi(per, page);
      // console.log(result);
      // console.log(result.addresses);
      result.addresses.forEach((item,i)=>{
        console.log(item._id);
        // console.log(this.arr);
        this.arr.push(item._id);
     
        console.log(item);
        this.list.push({id:i,address:item.regions,name:item.receiver,tel:item.mobile,isDefault:item.isDefault})
      
        })
      // console.log(result.address.addresses);
      // this.list = [{address:result.addresses,name:result.receiver,tel:result.mobile,isDefault:result.isDefault}];
      // this.list=result.addresses
   
    },
  
      //新增收货人信息
       onAdd() {
          this.$router.push("/address");
      Toast('新增地址');
    },
     onEdit(item, index) {
      Toast('编辑地址:' + index);
      // console.log(item);
      const id=this.arr[index];
      console.log(id);
      this.$router.push({ path: `/changereceipt/${id}` });
    },
  },
  created() {
    this.getreceipt();
  },
  mounted() {},
  components: {},
};
</script>
<style scoped></style>
